package com.yf.exam.modules.trainingarchives.evaluation.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.base.Preconditions;
import com.yf.exam.common.entity.Result;
import com.yf.exam.core.api.dto.BaseIdReqDTO;
import com.yf.exam.core.exception.ServiceException;
import com.yf.exam.modules.trainingarchives.evaluation.dto.EvaluationInfoDTO;
import com.yf.exam.modules.trainingarchives.evaluation.dto.EvaluationSummaryDTO;
import com.yf.exam.modules.trainingarchives.evaluation.entity.EvaluationSummary;
import com.yf.exam.modules.trainingarchives.evaluation.service.IEvaluationScoreService;
import com.yf.exam.modules.trainingarchives.evaluation.service.IEvaluationService;
import com.yf.exam.modules.trainingarchives.evaluation.service.IEvaluationSummaryService;
import com.yf.exam.modules.trainingarchives.evaluation.vo.EvaluationSummaryVO;
import com.yf.exam.modules.trainingarchives.teacherattendance.entity.TeacherAttendance;
import com.yf.exam.modules.trainingarchives.teacherattendance.vo.TeacherAttendanceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 满意度调查总结表 前端控制器
 * </p>
 *
 * @author lql
 * @since 2025-01-16
 */
@Api(tags={"满意度调查总结表"})
@RestController
@RequestMapping("/org/api/evaluation-summary")
public class EvaluationSummaryController {

    @Resource
    private IEvaluationSummaryService iEvaluationSummaryService;

    /**
     * 添加
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "保存满意度调查总结")
    @PostMapping(value = "/save")
    public Result<String> save(@Valid @RequestBody EvaluationSummaryDTO reqDTO) {
        try {
            //复制参数
            iEvaluationSummaryService.add(reqDTO);
            return Result.ok();
        }catch (ServiceException e){
            return Result.faild(e);
        }
    }

    @ApiOperation(value = "查询详情")
    @PostMapping (value = "/get")
    public Result<EvaluationSummaryVO> get(@RequestBody EvaluationSummaryDTO reqDTO) {
        Preconditions.checkArgument(!StringUtils.isBlank(reqDTO.getTrainingClassInfoId()), "培训id不能为空!");
        Preconditions.checkArgument(!(reqDTO.getType() == null ), "调查类型不能为空!");
        EvaluationSummary evaluationSummary = iEvaluationSummaryService.getOne(Wrappers.<EvaluationSummary>lambdaQuery()
                .eq(EvaluationSummary::getTrainingClassInfoId, reqDTO.getTrainingClassInfoId())
                .eq(EvaluationSummary::getType, reqDTO.getType()));
        EvaluationSummaryVO vo = new EvaluationSummaryVO();
        if (evaluationSummary == null) {
            vo.setType(reqDTO.getType());
            vo.setTrainingClassInfoId(reqDTO.getTrainingClassInfoId());
            return Result.ok(vo);
        }

        BeanUtils.copyProperties(evaluationSummary,vo);
        return Result.ok(vo);
    }

}
